package com.sddfp.log.config;

import com.sddfp.common.constant.mq.MQConstant;
import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {
    /**
     * 队列:    sddfp-queue-bind
     * 交换机:  sddfp-exchange-bind
     * 路由key: bind-card-message
     * 
     * 注意，需要加个死信队列，如果消息因为异常未能消费，可以到死信队列查看；？？？？？？？
     *
     */
    @Bean
    public Queue queueBind(){
        return QueueBuilder.durable(MQConstant.SDDFP_QUEUE_BIND).build();
    }
    @Bean
    public DirectExchange exchangeBind(){
        return new DirectExchange(MQConstant.SDDFP_EXCHANGE_BIND);
    }
    @Bean
    public Binding binding(Queue queueBind, DirectExchange exchangeBind) {
        return BindingBuilder.bind(queueBind).to(exchangeBind).with(MQConstant.BIND_CARD_MESSAGE);
    }

    /**
     * 消息序列化成JSON字符串
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

}
